package cn.iocoder.yudao.module.member.controller.admin.interviewInvite;

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.interviewInvite.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.interviewInvite.InterviewInviteDO;
import cn.iocoder.yudao.module.member.convert.interviewInvite.InterviewInviteConvert;
import cn.iocoder.yudao.module.member.service.interviewInvite.InterviewInviteService;

@Api(tags = "管理后台 -运营端- 面试邀约")
@RestController
@RequestMapping("/member/interview-invite")
@Validated
public class InterviewInviteController {

    @Resource
    private InterviewInviteService interviewInviteService;

    @PostMapping("/create")
    @ApiOperation("创建面试邀约")
    public CommonResult<Long> createInterviewInvite(@Valid @RequestBody InterviewInviteCreateReqVO createReqVO) {
        return success(interviewInviteService.createInterviewInvite(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新面试邀约")
    public CommonResult<Boolean> updateInterviewInvite(@Valid @RequestBody InterviewInviteUpdateReqVO updateReqVO) {
        interviewInviteService.updateInterviewInvite(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除面试邀约")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    public CommonResult<Boolean> deleteInterviewInvite(@RequestParam("id") Long id) {
        interviewInviteService.deleteInterviewInvite(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得面试邀约")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public CommonResult<InterviewInviteRespVO> getInterviewInvite(@RequestParam("id") Long id) {
        InterviewInviteDO interviewInvite = interviewInviteService.getInterviewInvite(id);
        return success(InterviewInviteConvert.INSTANCE.convert(interviewInvite));
    }

    @GetMapping("/list")
    @ApiOperation("获得面试邀约列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    public CommonResult<List<InterviewInviteRespVO>> getInterviewInviteList(@RequestParam("ids") Collection<Long> ids) {
        List<InterviewInviteDO> list = interviewInviteService.getInterviewInviteList(ids);
        return success(InterviewInviteConvert.INSTANCE.convertList(list));
    }

    @PostMapping("/page")
    @ApiOperation("获得面试邀约分页")
    public CommonResult<PageResult<InterviewInviteRespVO>> getInterviewInvitePage(@Valid @RequestBody InterviewInvitePageReqVO pageVO) {
        PageResult<InterviewInviteDO> pageResult = interviewInviteService.getInterviewInvitePage(pageVO);
        return success(InterviewInviteConvert.INSTANCE.convertPage(pageResult));
    }

    @PostMapping("/oper-page")
    @ApiOperation("获得面试邀约分页")
    @TenantIgnore
    public CommonResult<PageResult<InterviewInviteRespVO>> getInterviewInvitePage1(@Valid @RequestBody InterviewInvitePageReqVO pageVO) {
        PageResult<InterviewInviteDO> pageResult = interviewInviteService.getInterviewInvitePage(pageVO);
        return success(InterviewInviteConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出面试邀约 Excel")
    @OperateLog(type = EXPORT)
    public void exportInterviewInviteExcel(@Valid InterviewInviteExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<InterviewInviteDO> list = interviewInviteService.getInterviewInviteList(exportReqVO);
        // 导出 Excel
        List<InterviewInviteExcelVO> datas = InterviewInviteConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "面试邀约.xls", "数据", InterviewInviteExcelVO.class, datas);
    }

    @PostMapping("/admin/invitationRecord")
    @ApiOperation("获得面试邀约列表")
    public CommonResult<List<InterviewInviteRespVO>> invitationRecord(@Valid InterviewInviteReqVO reqVO) {
        List<InterviewInviteDO> list = interviewInviteService.getInterviewInviteList(reqVO);
        return success(InterviewInviteConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/admin/invitedFeedback")
    @ApiOperation("获得面试邀约反馈")
    public CommonResult<InterviewInviteRespVO> InvitedFeedback(@RequestParam("id") Long id) {
        return this.getInterviewInvite(id);
    }


}
